<?php

class Core_Backend_Component_Design_View_Page_Position_Index extends Core_Backend_Share_View_Grid {

    protected function buildToolbar($toolbar){
    	parent::buildToolbar($toolbar);
    	$group = $toolbar->createGroup();
        $group->addLink($this->getUrl(NULL, 'create'), $this->__('share.button.create'));
    }

    protected function buildGrid($grid) {
        $filter = new Kd_Object($this->getRequest()->getParameter('filter'));
        $grid->setId('template_grid')
                ->setPrimaryKey('id')
                ->setAllowFilter(TRUE)
                ->setSortField($this->getRequest()->getParameter('sort', 'id'))
                ->setSortDirection($this->getRequest()->getParameter('dir', 'asc'))
                ->setSortUrlFormat($this->getSortUrl());
        $grid->addLabelColumn($this->__('share.label.code'), 'code', '{code}')
                ->setTextboxFilter(NULL, NULL, $filter->getData('code'))
                ->setSortField('code');     
        $grid->addLabelColumn($this->__('share.label.name'), 'name', '{name}')
                ->setTextboxFilter(NULL, NULL, $filter->getData('name'))
                ->setSortField('name');
        $grid->addLabelColumn($this->__('share.label.template'), 'template', '{template_name}')
                ->setSelectFilter(NULL, NULL, $this->getTemplates(), 'name', 'id', $filter->getData('template'))
                ->setSortField('template');
        $grid->addLabelColumn($this->__('share.label.enable'), 'enabled', '{enabled}')
                ->setBooleanFilter(NULL, NULL, $filter->getData('enabled'))
                ->setSortField('enable')
                ->setAlign('center')
                ->setWidth(60);
        $grid->addLinkColumn('#', 'edit', $this->getUrl(array('id' => '{id}'), 'edit'), $this->__('share.button.edit'))
                ->setWidth(40)
                ->setAlign('center');
        $grid->setDataSource($this->getList()->toArray());
        parent::buildGrid($grid);
    }

    protected function buildPagination($pagination) {
        parent::buildPagination($pagination);
        $pagination->setUrlFormat($this->getPaginationUrl())
                ->setRecordCount($this->getRecords());
    }
}